<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>组织机构管理</title>
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <script type="text/javascript" src="/resource/common/js/common/xzqhLink.js"></script>
    <script type="text/javascript">
        var path = "${path}";
        $(function () {
            //初始化赋值
            setValue();
        });

        //获取父页面的值
        function setValue() {
            var name, value;
            var str = decodeURI(decodeURI(window.location.href));
            var num = str.indexOf("?")
            str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]
            // 设值
            var arr = str.split("&"); //各个参数放到数组里

            var orgAreaprov;//省初始化id
            var orgAreacity;//地市初始化id
            var orgAreacontry;

            for (var i = 0; i < arr.length; i++) {
                num = arr[i].indexOf("=");
                if (num > 0) {
                    name = arr[i].substring(0, num);
                    value = arr[i].substr(num + 1);
                    if ("id" == name) {
                        $("#id").val(value);
                    } else if ("sjcode" == name) {
                        $("#sjcode").val(value);
                    } else if ("sjname" == name) {
                        $("#sjname").val(value);
                    } else if ("orgCode" == name) {
                        $("#orgCode").val(value);
                    } else if ("orgName" == name) {
                        $("#orgName").val(value);
                    } else if ("orgAliases" == name) {
                        if( value != "null"){
                            $("#orgAliases").val(value);
                        }
                    } else if ("orgAreaprov" == name) {
                        orgAreaprov = value;
                    } else if ("orgAreacity" == name) {
                        orgAreacity = value;
                    } else if ("orgAreacontry" == name) {
                        orgAreacontry = value;
                    } else if ("businessAddress" == name) {
                        if( value != "null"){
                            $("#businessAddress").val(value);
                        }
                    } else if ("orgSort" == name) {
                        $("#orgSort").val(value);
                    } else if ("pcode" == name) {
                        $("#pcode").val(value);
                    }
                }
            }
            new xzqhLink({
                <%--basePath: "${path}",--%>
                provinceEle: $('#orgAreaprov'),
                cityEle: $('#orgAreacity'),
                districtEle: $('#orgAreacontry'),
                provinceInitialValue: orgAreaprov,//省初始化id
                cityInitialValue: orgAreacity,//地市初始化id
                districtInitialValue: orgAreacontry//区县初始化id
            });

            //重新渲染页面
            $.parser.parse();
        }

        //保存增加的数据
        function submit_Add() {
            if (!validform("jgForm")) {
                return;
            }
            if (!checkInput()) {
                return;
            }
            $.ajax({
                type: "POST",
                url: path + '/system/org/save',
                dataType: "json",
                data: $('#jgForm').serialize(),
                success: function callback(data) {
                    var analyMsg = data;
                    if (analyMsg.code != '0000') {
                        $.alert("default", "error", analyMsg.msg);
                    } else {
                        $.alert("update", "info", "组织机构信息");
                        setTimeout("closeLayer()", 800);
                    }
                },
                error: function (data, textstatus) {
                    $.alert("default", "error", analyMsg.msg);
                }
            });
        }
        function checkInput() {
            var orgSort = $("#orgSort").val();
            if (!(/^[0-9]*$/.test(orgSort))) {
                $.messager.alert('提示', '本级序号只能为数字。', 'info', function () {
                });
                return false;
            }
            if (orgSort.length > 10) {
                $.messager.alert('提示', '本级序号最大为10个数字。', 'info', function () {
                });
                return false;
            }

            var orgCode = $("#orgCode").val();
            if (!(/^[0-9]*$/.test(orgCode))) {
                $.messager.alert('提示', '机构代码只能为数字。', 'info', function () {
                });
                return false;
            }
            return true;
        }

    </script>
</head>
<body style="margin:0px; padding:0px;">
<%@ include file="/WEB-INF/jsp/loading.jsp" %>
<div class="easyui-layout" fit="true">
    <div id="AddDlgDiv" align="center">
        <form id="jgForm" method="post">
            <input type="hidden" id="id" name="id">
            <table class="f_table" cellspacing="1" style="width: 100%;">
                <tr>
                    <td align="right" class="s_bg" style="width:15%;">
                        上级机构代码：
                    </td>
                    <td align="left" style="width: 35%;">
                        <input type="text" id="sjcode" name="sjcode" style="width: 98%; border: none; background: transparent;" readonly="readonly"/>
                    </td>
                    <td align="right" class="s_bg" style="width: 15%;">
                        上级机构名称：
                    </td>
                    <td align="left" style="width: 35%;">
                        <input type="text" id="sjname" name="sjname" style="width: 98%; border: none; background: transparent;" readonly="readonly"/>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="s_bg">
                        机构代码：
                    </td>
                    <td align="left">
                        <input type="text" id="orgCode" name="orgCode" style="width: 98%;" class="easyui-validatebox"
                               data-options="required:true, validType:'length[0,20]'"/>
                    </td>
                    <td align="right" class="s_bg">
                        机构名称：
                    </td>
                    <td align="left">
                        <input type="text" id="orgName" name="orgName" style="width: 98%;" class="easyui-validatebox"
                               data-options="required:true,tipPosition:'left',validType:'length[0,50]'"/>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="s_bg">
                        机构简称：
                    </td>
                    <td align="left">
                        <input type="text" id="orgAliases" name="orgAliases" style="width: 98%;"
                               class="easyui-validatebox"
                               data-options="required:false,tipPosition:'left',validType:'length[0,50]'"/>
                    </td>
                    <td align="right" class="s_bg">
                        机构所在地：
                    </td>
                    <td align="left">
                        <select id="orgAreaprov" name="orgAreaprov" style="width: 32%;"></select>
                        <select id="orgAreacity" name="orgAreacity" style="width: 32%;"></select>
                        <select id="orgAreacontry" name="orgAreacontry" style="width: 32%;"></select>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="s_bg">
                        经营地址：
                    </td>
                    <td align="left">
                        <input type="text" id="businessAddress" name="businessAddress" style="width: 98%;"
                               class="easyui-validatebox"
                               data-options="required:false,validType:'length[0,100]',tipPosition:'left'"/>
                    </td>
                    <td align="right" class="s_bg">
                        本级序号：
                    </td>
                    <td align="left">
                        <input type="text" id="orgSort" name="orgSort" style="width: 98%;" class="easyui-validatebox"
                               data-options="required:true,validType:'int',tipPosition:'left'"/>
                    </td>
                </tr>
            </table>
            <input type="hidden" id="pcode" name="pcode" value=""/>
        </form>
        <div align="center" style="margin-top: 15px;">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submit_Add()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="closeLayer();">取消</a>
        </div>
    </div>
</div>
</body>
</html>
